package com.fpf.springboot.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.fpf.springboot.domain.Music;
import com.fpf.springboot.mapper.MusicMapper;
import com.fpf.springboot.service.MusicService;
@Service
public class MusicServiceImpl implements MusicService{
	@Autowired
	private MusicMapper musicMapper;
	
	@Cacheable(value="music")//存储在redis的缓存中，music.all作为key,List<Music>作为value
	public List<Music> findAllMusics() {
		System.out.println("redis没有music.all，经过findAllMusics方法");
		return musicMapper.findAllMusics();
	}

	@Override
	@Cacheable(value="music",key="'music_'+#musicId")
	public Music findMusicByMusicId(String musicId) {
		return musicMapper.findMusicByMusicId(musicId);
	}

	@Override
	/**
	 * value:主key
	 * key:副key
	 * condition:条件
	 */
	@CacheEvict(value="music",key="'music_'+#musicId",condition="#musicId!=null")
	public String deleteMusicByMusicId(String musicId) {
		System.out.println("执行此方法时，当前key从缓存中移除");
		return "删除成功";
	}

}
